package mo.offer_version2;

import mo.common.TreeNode;

import java.util.ArrayList;
import java.util.List;

public class L54 {

    public int kthLargest(TreeNode root, int k) {
        List<Integer> arr = new ArrayList<>();
        dfs(arr, root);
        return arr.get(arr.size()-k);
    }

    private void dfs(List<Integer> arr, TreeNode root) {
        if (root.left != null) {
            dfs(arr, root.left);
        }
        arr.add(root.val);
        if (root.right != null) {
            dfs(arr, root.right);
        }
    }

}
